Use Keras experiment to transfer style Watson Machine Learning icon
Icon

This notebook contains the steps and code required to demonstrate style transfer technique using Watson Machine Learning Service. This notebook introduces commands for getting data, training_definition persistence to Watson Machine Learning repository and model training.

Some familiarity with Python is helpful. This notebook uses Python 3.6 and Watson Studio environments.

Learning goals

In this notebook you learn to work with Watson Machine Learning experiments to train Deep Learning models (Keras).

Contents

  1. Set up
  2. Create the training definition
  3. Define the experiment
  4. Run the experiment
  5. Results
  6. Summary

1. Set up

Before you use the sample code in this notebook, you must perform the following setup tasks:

  • Create a Watson Machine Learning (WML) Service instance (a free plan is offered and information about how to create the instance is here).
  • Create a Cloud Object Storage (COS) instance (a lite plan is offered and information about how to order storage is here).
    Note: When using Watson Studio, you already have a COS instance associated with the project you are running the notebook in.
  • Create new credentials with HMAC:

    • Go to your COS dashboard.
    • In the Service credentials tab, click New Credential+.
    • Add the inline configuration parameter: {"HMAC":true}, click Add. (For more information, see HMAC.)

      This configuration parameter adds the following section to the instance credentials, (for use later in this notebook):

      "cos_hmac_keys": {
            "access_key_id": "-------",
            "secret_access_key": "-------"
       }

In this section:

1.1 Work with Cloud Object Storage (COS)

Import the Boto library, which allows Python developers to manage COS.

In [1]:
# Import the boto library
import ibm_boto3
from ibm_botocore.client import Config
import os
import json
import warnings
import urllib
import time
warnings.filterwarnings('ignore')

Authenticate to COS and define the endpoint you will use.

  1. Enter your COS credentials in the following cell. You can find these credentials in your COS instance dashboard under the Service credentials tab as described in the set up section.

  2. Go to the Endpoint tab in the COS instance's dashboard to get the endpoint information, for example: s3-api.us-geo.objectstorage.softlayer.net.

In [2]:
# Enter your COS credentials.
cos_credentials = {
  "apikey": "***",
  "cos_hmac_keys": {
    "access_key_id": "***",
    "secret_access_key": "***"
  },
  "endpoints": "https://cos-service.bluemix.net/endpoints",
  "iam_apikey_description": "***",
  "iam_apikey_name": "***",
  "iam_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Writer",
  "iam_serviceid_crn": "***",
  "resource_instance_id": "***"
}
In [3]:
api_key = cos_credentials['apikey']
service_instance_id = cos_credentials['resource_instance_id']
auth_endpoint = 'https://iam.bluemix.net/oidc/token'
# Enter your Endpoint information.
service_endpoint = 'https://s3-api.us-geo.objectstorage.softlayer.net'

Create the Boto resource by providing type, endpoint_url and credentials.

In [4]:
cos = ibm_boto3.resource('s3',
                         ibm_api_key_id=api_key,
                         ibm_service_instance_id=service_instance_id,
                         ibm_auth_endpoint=auth_endpoint,
                         config=Config(signature_version='oauth'),
                         endpoint_url=service_endpoint)

Create the buckets you will use to store training data and training results.

Note: Bucket names must be unique.

In [5]:
# Create two buckets, style-data-example and style-results-example
from uuid import uuid4

bucket_uid = str(uuid4())

buckets = ['style-data-example-' + bucket_uid, 'style-results-example-' + bucket_uid]
for bucket in buckets:
    if not cos.Bucket(bucket) in cos.buckets.all():
        print('Creating bucket "{}"...'.format(bucket))
        try:
            cos.create_bucket(Bucket=bucket)
        except ibm_boto3.exceptions.ibm_botocore.client.ClientError as e:
            print('Error: {}.'.format(e.response['Error']['Message']))
Creating bucket "style-data-example-1e6741d8-7b4c-470c-ac63-39dbdbdcb9dc"...
Creating bucket "style-results-example-1e6741d8-7b4c-470c-ac63-39dbdbdcb9dc"...

You have now created two new buckets:

  • style-data-example
  • style-results-example

Display a list of buckets for your COS instance to verify that the buckets were created.

In [6]:
# Display the buckets
print([x.name for x in list(cos.buckets.all()) if x.name.startswith('style')])
['style-data-example-1e6741d8-7b4c-470c-ac63-39dbdbdcb9dc', 'style-results-example-1e6741d8-7b4c-470c-ac63-39dbdbdcb9dc']

1.2 Download training data and upload it to COS buckets

Download your training data and upload them to the 'training-data' bucket. Then, create a list of links for the training dataset.

The following code snippet creates the STYLE_DATA folder and downloads the files from the links to the folder.

Tip: First, use the !pip install wget command to install the wget library:

In [7]:
!pip install --upgrade wget
Collecting wget
  Downloading https://files.pythonhosted.org/packages/47/6a/62e288da7bcda82b935ff0c6cfe542970f04e29c756b0e147251b2fb251f/wget-3.2.zip
Building wheels for collected packages: wget
  Building wheel for wget (setup.py) ... done
  Stored in directory: /home/dsxuser/.cache/pip/wheels/40/15/30/7d8f7cea2902b4db79e3fea550d7d7b85ecb27ef992b618f3f
Successfully built wget
Installing collected packages: wget
Successfully installed wget-3.2
In [8]:
import wget, os

# Create folder
data_dir = 'STYLE_DATA'
if not os.path.isdir(data_dir):
    os.mkdir(data_dir)

links = ['https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5',
         'https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg/1513px-Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg',
         'https://upload.wikimedia.org/wikipedia/commons/5/52/Krak%C3%B3w_239a.jpg',
         'https://upload.wikimedia.org/wikipedia/commons/3/3f/Kandinsky%2C_Lyrisches.jpg']

# Download the links to the folder
for i in range(len(links)):
    if 'Gogh' in links[i]: 
        filepath = os.path.join(data_dir, 'van_gogh.jpg')
    elif 'Krak' in links[i]: 
        filepath = os.path.join(data_dir, 'krakow.jpg')
    elif 'Kandinsky' in links[i]:
        filepath = os.path.join(data_dir, 'kandinsky.jpg')
    else:
        filepath = os.path.join(data_dir, os.path.join(links[i].split('/')[-1]))

    if not os.path.isfile(filepath):
        print(links[i])
        urllib.request.urlretrieve(links[i], filepath)

# List the files in the STYLE_DATA folder        
!ls STYLE_DATA
https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5
https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg/1513px-Van_Gogh_-_Starry_Night_-_Google_Art_Project.jpg
https://upload.wikimedia.org/wikipedia/commons/5/52/Krak%C3%B3w_239a.jpg
https://upload.wikimedia.org/wikipedia/commons/3/3f/Kandinsky%2C_Lyrisches.jpg
kandinsky.jpg  van_gogh.jpg
krakow.jpg     vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5

Base image: Cracow - main market square

In [9]:
from IPython.display import Image
Image(filename=os.path.join(data_dir, 'krakow.jpg'), width=1000)
Out[9]:

Style image 1: Vincent Van Gogh - Starry Night

In [10]:
Image(filename=os.path.join(data_dir, 'van_gogh.jpg'), width=500)
Out[10]:

Style image 2: Kandinsky Lyrisches

In [11]:
Image(filename=os.path.join(data_dir, 'kandinsky.jpg'), width=600)
Out[11]:

Upload the data files to the created buckets.

In [12]:
bucket_name = buckets[0]
bucket_obj = cos.Bucket(bucket_name)
In [13]:
for filename in os.listdir(data_dir):
    with open(os.path.join(data_dir, filename), 'rb') as data: 
        bucket_obj.upload_file(os.path.join(data_dir, filename), filename)
        print('{} is uploaded.'.format(filename))
krakow.jpg is uploaded.
vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5 is uploaded.
van_gogh.jpg is uploaded.
kandinsky.jpg is uploaded.

Let's see the list of all the buckets and their contents.

In [14]:
for obj in bucket_obj.objects.all():
    print('Object key: {}'.format(obj.key))
    print('Object size (kb): {}'.format(obj.size/1024))
Object key: kandinsky.jpg
Object size (kb): 337.97265625
Object key: krakow.jpg
Object size (kb): 2063.50390625
Object key: van_gogh.jpg
Object size (kb): 833.9755859375
Object key: vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5
Object size (kb): 78256.46875

You are done with COS, and you are now ready to train your model!

1.3 Work with the Watson Machine Learning instance

Load the libraries you need.

In [15]:
import urllib3, requests, json, base64, time, os

Authenticate to the Watson Machine Learning (WML) service on IBM Cloud.

Tip: Authentication information (your credentials) can be found in the Service credentials tab of the service instance that you created on IBM Cloud. If there are no credentials listed for your instance in Service credentials, click New credential (+) and enter the information required to generate new authentication information.

Action: Enter your WML service instance credentials here.

In [16]:
wml_credentials = {
    "apikey": "***",
    "instance_id": "***",
    "url": "https://ibm-watson-ml.mybluemix.net"
}

Install the watson-machine-learning-client from pypi.

In [17]:
!pip install --upgrade watson-machine-learning-client
Collecting watson-machine-learning-client
  Downloading https://files.pythonhosted.org/packages/12/67/66db412f00d19bfdc5725078bff373787513bfb14320f2804b9db3abb53a/watson_machine_learning_client-1.0.378-py3-none-any.whl (536kB)
     |████████████████████████████████| 542kB 10.5MB/s eta 0:00:01
Requirement already satisfied, skipping upgrade: requests in /opt/conda/envs/Python36/lib/python3.6/site-packages (from watson-machine-learning-client) (2.21.0)
Requirement already satisfied, skipping upgrade: lomond in /opt/conda/envs/Python36/lib/python3.6/site-packages (from watson-machine-learning-client) (0.3.3)
Requirement already satisfied, skipping upgrade: pandas in /opt/conda/envs/Python36/lib/python3.6/site-packages (from watson-machine-learning-client) (0.24.1)
Requirement already satisfied, skipping upgrade: ibm-cos-sdk in /opt/conda/envs/Python36/lib/python3.6/site-packages (from watson-machine-learning-client) (2.4.3)
Requirement already satisfied, skipping upgrade: tqdm in /opt/conda/envs/Python36/lib/python3.6/site-packages (from watson-machine-learning-client) (4.31.1)
Requirement already satisfied, skipping upgrade: certifi in /opt/conda/envs/Python36/lib/python3.6/site-packages (from watson-machine-learning-client) (2020.4.5.1)
Requirement already satisfied, skipping upgrade: tabulate in /opt/conda/envs/Python36/lib/python3.6/site-packages (from watson-machine-learning-client) (0.8.2)
Requirement already satisfied, skipping upgrade: urllib3 in /opt/conda/envs/Python36/lib/python3.6/site-packages (from watson-machine-learning-client) (1.24.1)
Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /opt/conda/envs/Python36/lib/python3.6/site-packages (from requests->watson-machine-learning-client) (3.0.4)
Requirement already satisfied, skipping upgrade: idna<2.9,>=2.5 in /opt/conda/envs/Python36/lib/python3.6/site-packages (from requests->watson-machine-learning-client) (2.8)
Requirement already satisfied, skipping upgrade: six>=1.10.0 in /opt/conda/envs/Python36/lib/python3.6/site-packages (from lomond->watson-machine-learning-client) (1.12.0)
Requirement already satisfied, skipping upgrade: numpy>=1.12.0 in /opt/conda/envs/Python36/lib/python3.6/site-packages (from pandas->watson-machine-learning-client) (1.15.4)
Requirement already satisfied, skipping upgrade: python-dateutil>=2.5.0 in /opt/conda/envs/Python36/lib/python3.6/site-packages (from pandas->watson-machine-learning-client) (2.7.5)
Requirement already satisfied, skipping upgrade: pytz>=2011k in /opt/conda/envs/Python36/lib/python3.6/site-packages (from pandas->watson-machine-learning-client) (2018.9)
Requirement already satisfied, skipping upgrade: ibm-cos-sdk-core==2.*,>=2.0.0 in /opt/conda/envs/Python36/lib/python3.6/site-packages (from ibm-cos-sdk->watson-machine-learning-client) (2.4.3)
Requirement already satisfied, skipping upgrade: ibm-cos-sdk-s3transfer==2.*,>=2.0.0 in /opt/conda/envs/Python36/lib/python3.6/site-packages (from ibm-cos-sdk->watson-machine-learning-client) (2.4.3)
Requirement already satisfied, skipping upgrade: docutils>=0.10 in /opt/conda/envs/Python36/lib/python3.6/site-packages (from ibm-cos-sdk-core==2.*,>=2.0.0->ibm-cos-sdk->watson-machine-learning-client) (0.14)
Requirement already satisfied, skipping upgrade: jmespath<1.0.0,>=0.7.1 in /opt/conda/envs/Python36/lib/python3.6/site-packages (from ibm-cos-sdk-core==2.*,>=2.0.0->ibm-cos-sdk->watson-machine-learning-client) (0.9.3)
Installing collected packages: watson-machine-learning-client
  Found existing installation: watson-machine-learning-client 1.0.376
    Uninstalling watson-machine-learning-client-1.0.376:
      Successfully uninstalled watson-machine-learning-client-1.0.376
Successfully installed watson-machine-learning-client-1.0.378

Import the watson-machine-learning-client and authenticate to the service instance.

In [18]:
from watson_machine_learning_client import WatsonMachineLearningAPIClient
In [19]:
client = WatsonMachineLearningAPIClient(wml_credentials)
In [20]:
print(client.version)
1.0.378

Note: watson-machine-learning-client documentation can be found here.

2. Create the training definitions

2.1 Prepare the training definition metadata

Hint: The final effect depends on number of iterations, and that the number of iterations impacts the training time.

In [21]:
#Set the number of iterations.
iters = 1
In [22]:
model_definition_1_metadata = {
            client.repository.DefinitionMetaNames.NAME: "style transfer van gogh",
            client.repository.DefinitionMetaNames.FRAMEWORK_NAME: "tensorflow",
            client.repository.DefinitionMetaNames.FRAMEWORK_VERSION: "1.15",
            client.repository.DefinitionMetaNames.RUNTIME_NAME: "python",
            client.repository.DefinitionMetaNames.RUNTIME_VERSION: "3.6",
            client.repository.DefinitionMetaNames.EXECUTION_COMMAND: "python style_transfer.py krakow.jpg van_gogh.jpg krakow --iter " + str(iters)
            }
In [23]:
model_definition_2_metadata = {
            client.repository.DefinitionMetaNames.NAME: "style transfer kandinsky",
            client.repository.DefinitionMetaNames.FRAMEWORK_NAME: "tensorflow",
            client.repository.DefinitionMetaNames.FRAMEWORK_VERSION: "1.15",
            client.repository.DefinitionMetaNames.RUNTIME_NAME: "python",
            client.repository.DefinitionMetaNames.RUNTIME_VERSION: "3.6",
            client.repository.DefinitionMetaNames.EXECUTION_COMMAND: "python style_transfer.py krakow.jpg kandinsky.jpg krakow --iter " + str(iters)
            }

2.2 Get the sample model definition content files from Git

In [24]:
!rm -rf STYLE.zip
In [25]:
filename_definition = 'STYLE.zip'

if not os.path.isfile(filename_definition):
    !wget https://github.com/pmservice/wml-sample-models/raw/master/keras/style/definition/STYLE.zip
    
!ls STYLE.zip
--2020-05-14 22:11:24--  https://github.com/pmservice/wml-sample-models/raw/master/keras/style/definition/STYLE.zip
Resolving github.com (github.com)... 140.82.113.4
Connecting to github.com (github.com)|140.82.113.4|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/pmservice/wml-sample-models/master/keras/style/definition/STYLE.zip [following]
--2020-05-14 22:11:24--  https://raw.githubusercontent.com/pmservice/wml-sample-models/master/keras/style/definition/STYLE.zip
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 199.232.8.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|199.232.8.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4555 (4.4K) [application/zip]
Saving to: ‘STYLE.zip’

100%[======================================>] 4,555       --.-K/s   in 0s      

2020-05-14 22:11:24 (15.6 MB/s) - ‘STYLE.zip’ saved [4555/4555]

STYLE.zip

2.3 Store the training definition in the WML repository

Store definition 1

In [26]:
definition_details = client.repository.store_definition(filename_definition, model_definition_1_metadata)

definition_url = client.repository.get_definition_url(definition_details)
definition_uid = client.repository.get_definition_uid(definition_details)
print(definition_url)
https://us-south.ml.cloud.ibm.com/v3/ml_assets/training_definitions/45efec3d-9ba7-4c9d-a105-2689d265f356

Store definition 2

In [27]:
definition_2_details = client.repository.store_definition(filename_definition, model_definition_2_metadata)

definition_2_url = client.repository.get_definition_url(definition_2_details)
definition_2_uid = client.repository.get_definition_uid(definition_2_details)
print(definition_2_url)
https://us-south.ml.cloud.ibm.com/v3/ml_assets/training_definitions/28710538-d495-40a4-81de-de6bb9b77bd9

List the stored definitions

In [28]:
client.repository.list_definitions()
------------------------------------  ------------------------  ------------------------  ----------
GUID                                  NAME                      CREATED                   FRAMEWORK
28710538-d495-40a4-81de-de6bb9b77bd9  style transfer kandinsky  2020-05-14T22:11:28.599Z  tensorflow
45efec3d-9ba7-4c9d-a105-2689d265f356  style transfer van gogh   2020-05-14T22:11:26.215Z  tensorflow
fdb718d3-4b41-4e3d-8c7e-5647678681c0  cycle_gan_training        2020-05-11T19:20:28.206Z  pytorch
48a113ac-40b7-41a9-b9f4-de91b38c824d  cycle_gan_training        2020-05-11T19:08:20.994Z  pytorch
f7567f0a-5f19-4f3a-ab3f-f00830fe4a0b  cycle_gan_training        2020-05-11T19:07:31.061Z  pytorch
9701c698-058a-4c28-bec7-e48854202e28  cycle_gan_training        2020-05-11T18:27:47.783Z  pytorch
aa5b5bbc-159b-4ab9-8c10-69ab8dc0a010  cycle_gan_training        2020-05-11T17:56:31.119Z  pytorch
fa5f43f9-df84-4cda-b434-0382aecce9fe  cycle_gan_training        2020-05-11T17:49:56.987Z  pytorch
839cbba2-d290-4841-b7d4-6be63d4127ff  cycle_gan_training        2020-05-11T14:53:08.587Z  pytorch
a6857dbd-f2fa-4fba-a738-e018c650307f  cycle_gan_training        2020-05-08T21:07:12.807Z  pytorch
------------------------------------  ------------------------  ------------------------  ----------

3. Create the experiment definition

Get a list of supported configuration parameters.

In [29]:
client.repository.ExperimentMetaNames.show()
--------------------------  ----  --------
META_PROP NAME              TYPE  REQUIRED
NAME                        str   Y
DESCRIPTION                 str   N
TAGS                        list  N
AUTHOR_NAME                 str   N
EVALUATION_METHOD           str   N
EVALUATION_METRICS          list  N
TRAINING_REFERENCES         list  Y
TRAINING_DATA_REFERENCE     dict  Y
TRAINING_RESULTS_REFERENCE  dict  Y
--------------------------  ----  --------

Create an experiment, which will train two models based on previously stored definitions.

In [30]:
TRAINING_DATA_REFERENCE = {
                            "connection": {
                                "endpoint_url": service_endpoint,
                                "access_key_id": cos_credentials['cos_hmac_keys']['access_key_id'],
                                "secret_access_key": cos_credentials['cos_hmac_keys']['secret_access_key']
                            },
                            "source": {
                                "bucket": buckets[0],
                            },
                            "type": "s3"
                        }
In [31]:
TRAINING_RESULTS_REFERENCE = {
                            "connection": {
                                "endpoint_url": service_endpoint,
                                "access_key_id": cos_credentials['cos_hmac_keys']['access_key_id'],
                                "secret_access_key": cos_credentials['cos_hmac_keys']['secret_access_key']
                            },
                            "target": {
                                "bucket": buckets[1],
                            },
                            "type": "s3"
                        }
In [32]:
experiment_metadata = {
            client.repository.ExperimentMetaNames.NAME: "STYLE experiment",
            client.repository.ExperimentMetaNames.TRAINING_DATA_REFERENCE: TRAINING_DATA_REFERENCE,
            client.repository.ExperimentMetaNames.TRAINING_RESULTS_REFERENCE: TRAINING_RESULTS_REFERENCE,
            client.repository.ExperimentMetaNames.TRAINING_REFERENCES: [
                        {
                            "name": "van gogh - cracow",
                            "training_definition_url": definition_url,
                            "compute_configuration": {"name": "k80x4"}
                        },
                        {
                            "name": "kandinsky - cracow",
                            "training_definition_url": definition_2_url,
                            "compute_configuration": {"name": "k80x4"}
                        },
                    ],
                }

Store the experiment in the WML repository.

In [33]:
# Store the experiment and display the experiment_uid.
experiment_details = client.repository.store_experiment(meta_props=experiment_metadata)

experiment_uid = client.repository.get_experiment_uid(experiment_details)
print(experiment_uid)
a5dfbf0f-6819-4d5e-bb34-3e2e340858cf

List the stored experiments.

In [34]:
client.repository.list_experiments()
------------------------------------  ----------------  ------------------------
GUID                                  NAME              CREATED
a5dfbf0f-6819-4d5e-bb34-3e2e340858cf  STYLE experiment  2020-05-14T22:11:31.111Z
------------------------------------  ----------------  ------------------------

Get the experiment definition details

In [35]:
details = client.repository.get_experiment_details(experiment_uid)

4. Run the experiment

Tip: To run the experiment in the background, set the optional parameter asynchronous=True (or remove it).

In [36]:
experiment_run_details = client.experiments.run(experiment_uid, asynchronous=False)

#########################################################

Running 'a5dfbf0f-6819-4d5e-bb34-3e2e340858cf' experiment

#########################################################


Experiment run uid: 6d3a75b7-1a7a-4549-9b65-30f13c7c9441

0%   - Processing model-7xcwjiwc (1/2): experiment_state=pending, training_state=pending
0%   - Processing model-7xcwjiwc (1/2): experiment_state=running, training_state=running
0%   - Processing model-7xcwjiwc (1/2): experiment_state=running, training_state=completed
50%  - Processing model-kbnkfc56 (2/2): experiment_state=running, training_state=pending
50%  - Processing model-kbnkfc56 (2/2): experiment_state=running, training_state=running
100% - Processing model-kbnkfc56 (2/2): experiment_state=completed, training_state=completed
100% - Finished processing training runs: experiment_state=completed


--------------------------------------------------------------------
Run of 'a5dfbf0f-6819-4d5e-bb34-3e2e340858cf' finished successfully.
--------------------------------------------------------------------


In [37]:
client.experiments.list_runs()
------------------------------------  ------------------------------------  -----------------  ---------  ------------------------
GUID (experiment)                     GUID (run)                            NAME (experiment)  STATE      CREATED
a5dfbf0f-6819-4d5e-bb34-3e2e340858cf  6d3a75b7-1a7a-4549-9b65-30f13c7c9441  STYLE experiment   completed  2020-05-14T22:11:31.727Z
------------------------------------  ------------------------------------  -----------------  ---------  ------------------------

As you can see, the experiment run has finished.

Get the experiment run UID.

In [38]:
experiment_run_id = client.experiments.get_run_uid(experiment_run_details)
print(experiment_run_id)
6d3a75b7-1a7a-4549-9b65-30f13c7c9441

Get the run details.

The code in the following cell gets details about a particular experiment run.

In [39]:
run_details = client.experiments.get_run_details(experiment_run_id)
In [40]:
run_details
Out[40]:
{'entity': {'experiment_run_status': {'current_at': '2020-05-14T22:11:31.950Z',
   'current_iteration': 1,
   'state': 'completed',
   'submitted_at': '2020-05-14T22:11:31.950Z'},
  'training_statuses': [{'current_at': '2020-05-14T22:14:45.449Z',
    'finished_at': '2020-05-14T22:14:21.709Z',
    'message': 'training-SSJG5tgMg: ',
    'metrics': [],
    'results': {'reference': {'connection': {'access_key_id': '8f068efcca214afcbd560b8793d07c6b',
       'endpoint_url': 'https://s3-api.us-geo.objectstorage.softlayer.net',
       'secret_access_key': 'ac2cb19d1df39ff9749d23a5a251f0e74ec651b6102d0657'},
      'location': {'bucket': 'style-results-example-1e6741d8-7b4c-470c-ac63-39dbdbdcb9dc',
       'file_name': 'model-7xcwjiwc',
       'model_location': 'training-SSJG5tgMg'},
      'type': 's3'}},
    'running_at': '2020-05-14T22:12:11.150Z',
    'state': 'completed',
    'submitted_at': '2020-05-14T22:11:34.047Z',
    'training_definition_url': 'https://us-south.ml.cloud.ibm.com/v3/ml_assets/training_definitions/45efec3d-9ba7-4c9d-a105-2689d265f356',
    'training_guid': 'model-7xcwjiwc',
    'training_reference_name': 'van gogh - cracow',
    'training_url': '/v3/models/model-7xcwjiwc'},
   {'current_at': '2020-05-14T22:24:37.491Z',
    'finished_at': '2020-05-14T22:23:40.646Z',
    'message': 'training-DFJG5pRMR: ',
    'metrics': [],
    'results': {'reference': {'connection': {'access_key_id': '8f068efcca214afcbd560b8793d07c6b',
       'endpoint_url': 'https://s3-api.us-geo.objectstorage.softlayer.net',
       'secret_access_key': 'ac2cb19d1df39ff9749d23a5a251f0e74ec651b6102d0657'},
      'location': {'bucket': 'style-results-example-1e6741d8-7b4c-470c-ac63-39dbdbdcb9dc',
       'file_name': 'model-kbnkfc56',
       'model_location': 'training-DFJG5pRMR'},
      'type': 's3'}},
    'running_at': '2020-05-14T22:21:27.964Z',
    'state': 'completed',
    'submitted_at': '2020-05-14T22:11:33.960Z',
    'training_definition_url': 'https://us-south.ml.cloud.ibm.com/v3/ml_assets/training_definitions/28710538-d495-40a4-81de-de6bb9b77bd9',
    'training_guid': 'model-kbnkfc56',
    'training_reference_name': 'kandinsky - cracow',
    'training_url': '/v3/models/model-kbnkfc56'}]},
 'experiment': {'guid': 'a5dfbf0f-6819-4d5e-bb34-3e2e340858cf',
  'url': '/v3/experiments/a5dfbf0f-6819-4d5e-bb34-3e2e340858cf'},
 'metadata': {'created_at': '2020-05-14T22:11:31.727Z',
  'guid': '6d3a75b7-1a7a-4549-9b65-30f13c7c9441',
  'modified_at': '2020-05-14T22:11:31.727Z',
  'url': '/v3/experiments/a5dfbf0f-6819-4d5e-bb34-3e2e340858cf/runs/6d3a75b7-1a7a-4549-9b65-30f13c7c9441'}}

Get the experiment run status.

Call client.experiments.get_status(run_uid) to check the experiment run status. This is useful when you run an experiment in the background.

In [41]:
status = client.experiments.get_status(experiment_run_id)
print(status)
{'current_at': '2020-05-14T22:11:31.950Z', 'current_iteration': 1, 'state': 'completed', 'submitted_at': '2020-05-14T22:11:31.950Z'}

Monitor the experiment run.

Call client.experiments.monitor_logs(run_uid) to monitor the experiment run. This method streams the training logs content to the console.

In [42]:
client.experiments.monitor_logs(experiment_run_id)

########################################################################

Monitor started for experiment run: 6d3a75b7-1a7a-4549-9b65-30f13c7c9441

########################################################################




####################################################

Log monitor started for training run: model-7xcwjiwc

####################################################


Training with training/test data at:
  DATA_DIR: /mnt/data/style-data-example-1e6741d8-7b4c-470c-ac63-39dbdbdcb9dc
  MODEL_DIR: /job/model-code
  TRAINING_JOB: 
  TRAINING_COMMAND: python style_transfer.py krakow.jpg van_gogh.jpg krakow --iter 1
Storing trained model at:
  RESULT_DIR: /mnt/results/style-results-example-1e6741d8-7b4c-470c-ac63-39dbdbdcb9dc/training-SSJG5tgMg
Thu May 14 22:12:15 UTC 2020: Running Tensorflow job
2020-05-14 22:12:15.537775: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
Using TensorFlow backend.
WARNING: Logging before flag parsing goes to stderr.
W0514 22:12:18.942937 139950699976512 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:541: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

W0514 22:12:18.945721 139950699976512 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:66: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

W0514 22:12:18.946261 139950699976512 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:4432: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.

W0514 22:12:18.964079 139950699976512 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:4267: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.

W0514 22:12:21.130596 139950699976512 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:190: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.

W0514 22:12:21.131323 139950699976512 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:197: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.

W0514 22:12:21.131657 139950699976512 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:203: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

2020-05-14 22:12:21.132050: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 AVX512F FMA
2020-05-14 22:12:21.158658: I tensorflow/core/platform/profile_utils/cpu_utils.cc:101] CPU Frequency: 2200000000 Hz
2020-05-14 22:12:21.162597: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x561d5dc8d420 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-05-14 22:12:21.162660: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-05-14 22:12:21.164425: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2020-05-14 22:12:31.541516: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 0 with properties: 
name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235
pciBusID: 0000:b1:00.0
2020-05-14 22:12:31.542831: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 1 with properties: 
name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235
pciBusID: 0000:b2:00.0
2020-05-14 22:12:31.543735: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 2 with properties: 
name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235
pciBusID: 0000:da:00.0
2020-05-14 22:12:31.544606: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 3 with properties: 
name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235
pciBusID: 0000:db:00.0
2020-05-14 22:12:31.544640: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-05-14 22:12:31.546218: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-05-14 22:12:31.547810: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-05-14 22:12:31.548106: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-05-14 22:12:31.549733: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-05-14 22:12:31.550742: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-05-14 22:12:31.554344: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-05-14 22:12:31.561124: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1767] Adding visible gpu devices: 0, 1, 2, 3
2020-05-14 22:12:31.561169: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-05-14 22:12:32.740172: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1180] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-05-14 22:12:32.740233: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1186]      0 1 2 3 
2020-05-14 22:12:32.740244: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 0:   N Y Y Y 
2020-05-14 22:12:32.740250: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 1:   Y N Y Y 
2020-05-14 22:12:32.740257: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 2:   Y Y N Y 
2020-05-14 22:12:32.740263: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 3:   Y Y Y N 
2020-05-14 22:12:32.745679: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1325] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10751 MB memory) -> physical GPU (device: 0, name: Tesla K80, pci bus id: 0000:b1:00.0, compute capability: 3.7)
2020-05-14 22:12:32.747917: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1325] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 10751 MB memory) -> physical GPU (device: 1, name: Tesla K80, pci bus id: 0000:b2:00.0, compute capability: 3.7)
2020-05-14 22:12:32.749994: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1325] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:2 with 10751 MB memory) -> physical GPU (device: 2, name: Tesla K80, pci bus id: 0000:da:00.0, compute capability: 3.7)
2020-05-14 22:12:32.752172: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1325] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:3 with 10751 MB memory) -> physical GPU (device: 3, name: Tesla K80, pci bus id: 0000:db:00.0, compute capability: 3.7)
2020-05-14 22:12:32.756130: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x561d7f2711b0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-05-14 22:12:32.756157: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Tesla K80, Compute Capability 3.7
2020-05-14 22:12:32.756165: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (1): Tesla K80, Compute Capability 3.7
2020-05-14 22:12:32.756172: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (2): Tesla K80, Compute Capability 3.7
2020-05-14 22:12:32.756179: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (3): Tesla K80, Compute Capability 3.7
W0514 22:12:32.760332 139950699976512 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:207: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead.

W0514 22:12:32.760979 139950699976512 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:216: The name tf.is_variable_initialized is deprecated. Please use tf.compat.v1.is_variable_initialized instead.

W0514 22:12:33.084962 139950699976512 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:223: The name tf.variables_initializer is deprecated. Please use tf.compat.v1.variables_initializer instead.

W0514 22:12:33.527887 139950699976512 variables.py:2627] Variable += will be deprecated. Use variable.assign_add if you want assignment to the variable value or 'x = x + y' if you want a new python Tensor object.
W0514 22:12:33.672205 139950699976512 deprecation.py:323] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/tensorflow_core/python/ops/math_grad.py:1375: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
2020-05-14 22:12:35.016153: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-05-14 22:12:35.168328: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
Model loaded.
Start of iteration 0
Current loss value: 7054192600.0
Image saved as krakow_at_iteration_0.png
Iteration 0 completed in 39s



####################################################

Log monitor started for training run: model-kbnkfc56

####################################################


Training with training/test data at:
  DATA_DIR: /mnt/data/style-data-example-1e6741d8-7b4c-470c-ac63-39dbdbdcb9dc
  MODEL_DIR: /job/model-code
  TRAINING_JOB: 
  TRAINING_COMMAND: python style_transfer.py krakow.jpg kandinsky.jpg krakow --iter 1
Storing trained model at:
  RESULT_DIR: /mnt/results/style-results-example-1e6741d8-7b4c-470c-ac63-39dbdbdcb9dc/training-DFJG5pRMR
Thu May 14 22:21:31 UTC 2020: Running Tensorflow job
2020-05-14 22:21:31.426804: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
Using TensorFlow backend.
WARNING: Logging before flag parsing goes to stderr.
W0514 22:21:34.349769 139909178881856 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:541: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.

W0514 22:21:34.352348 139909178881856 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:66: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.

W0514 22:21:34.352842 139909178881856 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:4432: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.

W0514 22:21:34.368018 139909178881856 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:4267: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.

W0514 22:21:36.828433 139909178881856 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:190: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.

W0514 22:21:36.829696 139909178881856 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:197: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.

W0514 22:21:36.829962 139909178881856 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:203: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

2020-05-14 22:21:36.830424: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 AVX512F FMA
2020-05-14 22:21:36.863277: I tensorflow/core/platform/profile_utils/cpu_utils.cc:101] CPU Frequency: 2300000000 Hz
2020-05-14 22:21:36.870372: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55b5c67602c0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-05-14 22:21:36.870438: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-05-14 22:21:36.874493: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2020-05-14 22:21:47.500199: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 0 with properties: 
name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235
pciBusID: 0000:b1:00.0
2020-05-14 22:21:47.502324: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 1 with properties: 
name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235
pciBusID: 0000:b2:00.0
2020-05-14 22:21:47.503386: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 2 with properties: 
name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235
pciBusID: 0000:da:00.0
2020-05-14 22:21:47.504419: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Found device 3 with properties: 
name: Tesla K80 major: 3 minor: 7 memoryClockRate(GHz): 0.8235
pciBusID: 0000:db:00.0
2020-05-14 22:21:47.504458: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-05-14 22:21:47.506400: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-05-14 22:21:47.508226: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-05-14 22:21:47.508501: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-05-14 22:21:47.510088: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-05-14 22:21:47.510994: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-05-14 22:21:47.514321: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-05-14 22:21:47.520174: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1767] Adding visible gpu devices: 0, 1, 2, 3
2020-05-14 22:21:47.520212: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-05-14 22:21:48.509366: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1180] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-05-14 22:21:48.509415: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1186]      0 1 2 3 
2020-05-14 22:21:48.509423: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 0:   N Y Y Y 
2020-05-14 22:21:48.509429: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 1:   Y N Y Y 
2020-05-14 22:21:48.509434: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 2:   Y Y N Y 
2020-05-14 22:21:48.509439: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1199] 3:   Y Y Y N 
2020-05-14 22:21:48.514309: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1325] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10751 MB memory) -> physical GPU (device: 0, name: Tesla K80, pci bus id: 0000:b1:00.0, compute capability: 3.7)
2020-05-14 22:21:48.516262: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1325] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 10751 MB memory) -> physical GPU (device: 1, name: Tesla K80, pci bus id: 0000:b2:00.0, compute capability: 3.7)
2020-05-14 22:21:48.517980: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1325] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:2 with 10751 MB memory) -> physical GPU (device: 2, name: Tesla K80, pci bus id: 0000:da:00.0, compute capability: 3.7)
2020-05-14 22:21:48.519732: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1325] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:3 with 10751 MB memory) -> physical GPU (device: 3, name: Tesla K80, pci bus id: 0000:db:00.0, compute capability: 3.7)
2020-05-14 22:21:48.522546: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x55b5e78f40c0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-05-14 22:21:48.522599: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Tesla K80, Compute Capability 3.7
2020-05-14 22:21:48.522622: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (1): Tesla K80, Compute Capability 3.7
2020-05-14 22:21:48.522643: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (2): Tesla K80, Compute Capability 3.7
2020-05-14 22:21:48.522662: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (3): Tesla K80, Compute Capability 3.7
W0514 22:21:48.529344 139909178881856 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:207: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead.

W0514 22:21:48.530064 139909178881856 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:216: The name tf.is_variable_initialized is deprecated. Please use tf.compat.v1.is_variable_initialized instead.

W0514 22:21:48.811929 139909178881856 module_wrapper.py:139] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:223: The name tf.variables_initializer is deprecated. Please use tf.compat.v1.variables_initializer instead.

W0514 22:21:49.234990 139909178881856 variables.py:2627] Variable += will be deprecated. Use variable.assign_add if you want assignment to the variable value or 'x = x + y' if you want a new python Tensor object.
W0514 22:21:49.353023 139909178881856 deprecation.py:323] From /opt/anaconda/envs/wmlce/lib/python3.6/site-packages/tensorflow_core/python/ops/math_grad.py:1375: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
2020-05-14 22:21:50.563552: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-05-14 22:21:50.678393: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
Model loaded.
Start of iteration 0
Current loss value: 4639754000.0
Image saved as krakow_at_iteration_0.png
Iteration 0 completed in 40s



-----------------
Log monitor done.
-----------------


List the training runs triggered by experiment run.

In [43]:
client.experiments.list_training_runs(experiment_run_id)
---------------  ------------------  ---------  ------------------------  ------------------------  -----------
GUID (training)  NAME                STATE      SUBMITTED                 FINISHED                  PERFORMANCE
model-7xcwjiwc   van gogh - cracow   completed  2020-05-14T22:11:34.047Z  2020-05-14T22:14:21.709Z  -
model-kbnkfc56   kandinsky - cracow  completed  2020-05-14T22:11:33.960Z  2020-05-14T22:23:40.646Z  -
---------------  ------------------  ---------  ------------------------  ------------------------  -----------

As you can see, two training runs completed.

In [44]:
training_uids = client.experiments.get_training_uids(experiment_run_details)
In [45]:
# List the training uids.
training_uids = [run_details['entity']['training_statuses'][i]['results']['reference']['location']['model_location'] for i in [0,1]]
print(training_uids)
['training-SSJG5tgMg', 'training-DFJG5pRMR']

5. Results - transferred styles images

In [46]:
bucket_name = buckets[1]
bucket_obj = cos.Bucket(bucket_name)
In [47]:
transfered_images = []

for uid in training_uids:
    obj = bucket_obj.Object(uid + '/transfered_images/krakow_at_iteration_' + str(iters-1) + '.png')
    filename = 'krakow_transfered_' + str(uid) + '.jpg'
    transfered_images.append(filename)
    with open(filename, 'wb') as data:
        obj.download_fileobj(data)
    print(filename)
krakow_transfered_training-SSJG5tgMg.jpg
krakow_transfered_training-DFJG5pRMR.jpg

Cracow

Have a look at the original picture again.

In [48]:
Image(filename=os.path.join(data_dir, 'krakow.jpg'), width=1000)
Out[48]:

Cracow + Van Gogh, Cracow + Kandinsky

Display the pictures after Van Gogh and Kandinsky styles have been applied.

In [49]:
Image(filename=transfered_images[1], width=1000)
Out[49]:
In [50]:
Image(filename=transfered_images[0], width=1000)
Out[50]:

6. Summary

You successfully completed this notebook! You learned how to use watson-machine-learning-client to run experiments. Check out our:

Citations

Author

Lukasz Cmielowski, PhD, is an Automation Architect and Data Scientist at IBM with a track record of developing enterprise-level applications that substantially increases clients' ability to turn data into actionable knowledge.


Copyright © 2018-2020 IBM. This notebook and its source code are released under the terms of the MIT License.

Love this notebook? Don't have an account yet?
Share it with your colleagues and help them discover the power of Watson Studio! Sign Up